
package com.tool.btn;

import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;
import io.netty.util.internal.StringUtil;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.net.URI;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.GoodDetailedJpanel;
import org.come.Jpanel.MonthlyCardJpanel;
import org.come.bean.BuyShopBean;
import org.come.bean.LoginResult;
import org.come.entity.Goodstable;
import org.come.model.Eshop;
import org.come.socket.Agreement;
import org.come.socket.DownLoadTxt;
import org.come.socket.SendMessageUntil;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.GsonUtil;
import org.come.until.UserMessUntil;

public class CommonBtn extends MoBanBtn {
    private int caozuo;
    private GoodDetailedJpanel goodDetailedJpanel;
    private MonthlyCardJpanel monthlyCardJpanel;
    private int wupinCount;

    public CommonBtn(String iconpath, int type) {
        super(iconpath, type);
    }

    public CommonBtn(String iconpath, int type, String text, int caozuo) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.setText(text);
        if (caozuo != 8 && caozuo != 9) {
            this.setFont(UIUtils.TEXT_HY16);
            this.setForeground(UIUtils.COLOR_BTNPUTONG[0]);
        } else {
            this.setFont(UIUtils.TEXT_FONT);
            this.setForeground(Color.white);
        }

        this.setVerticalTextPosition(0);
        this.setHorizontalTextPosition(0);
    }

    public CommonBtn(String iconpath, int type, String text, int caozuo, GoodDetailedJpanel goodDetailedJpanel) {
        super(iconpath, type);
        this.caozuo = caozuo;
        this.goodDetailedJpanel = goodDetailedJpanel;
        this.setText(text);
        this.setFont(UIUtils.TEXT_HY88);
        this.setForeground(UIUtils.COLOR_BTNPUTONG[0]);
        this.setVerticalTextPosition(0);
        this.setHorizontalTextPosition(0);
    }
    public CommonBtn(String iconpath, int type, String text, int caozuo, GoodDetailedJpanel goodDetailedJpanel,String SM) {
    	super(iconpath, type);
    	this.caozuo = caozuo;
    	this.goodDetailedJpanel = goodDetailedJpanel;
    	this.setText(text);
    	this.setFont(UIUtils.TEXT_HY88);
    	this.setForeground(UIUtils.COLOR_BLACK[0]);
    	this.setVerticalTextPosition(0);
    	this.setHorizontalTextPosition(0);
    }

    public CommonBtn(String iconpath, int type, String text, int caozuo, MonthlyCardJpanel monthlyCardJpanel) {
        super(iconpath, type);
        this.setText(text);
        this.setFont(UIUtils.TEXT_HY16);
        this.setForeground(UIUtils.COLOR_BTNPUTONG[0]);
        this.setVerticalTextPosition(0);
        this.setHorizontalTextPosition(0);
        this.caozuo = caozuo;
        this.monthlyCardJpanel = monthlyCardJpanel;
    }
    
    public CommonBtn(String iconpath, int type, String text, int caozuo, MonthlyCardJpanel monthlyCardJpanel,String sm) {
    	super(iconpath, type);
    	this.setText(text);
    	this.setFont(UIUtils.TEXT_HY16);
    	this.setForeground(UIUtils.COLOR_BLACK[0]);
    	this.setVerticalTextPosition(0);
    	this.setHorizontalTextPosition(0);
    	this.caozuo = caozuo;
    	this.monthlyCardJpanel = monthlyCardJpanel;
    }


    public void chooseyes() {
    }

    @Override
    public void chooseno() {
    }

    @Override
    public void nochoose(MouseEvent e) {
        if(this.caozuo == 9920){
            String mes = Agreement.getAgreement().rolechangeAgreement("钻石特权");
            SendMessageUntil.toServer(mes);
        }else if(this.caozuo == 9921){
            String mes = Agreement.getAgreement().rolechangeAgreement("至尊特权");
            SendMessageUntil.toServer(mes);
        }else
        if (this.caozuo >= 1 && this.caozuo <= 3) {
            if ("".equals(this.goodDetailedJpanel.getGoumaiCount().getText().trim())) {
                ZhuFrame.getZhuJpanel().addPrompt2("数量不能为空");
                return;
            }

            this.wupinCount = Integer.valueOf(this.goodDetailedJpanel.getGoumaiCount().getText());
            Eshop eshop = this.goodDetailedJpanel.getEshop();
            if (eshop == null) {
                return;
            }

            if (this.caozuo == 1) {
                int sum = Integer.parseInt(this.goodDetailedJpanel.getGoumaiCount().getText());
                if (sum <= 0) {
                    ZhuFrame.getZhuJpanel().addPrompt2("购买数量必须大于零");
                    return;
                }

                Goodstable goodstable = UserMessUntil.getgoodstable(new BigDecimal(eshop.getEshopiid()));
                int max = GoodsListFromServerUntil.Surplussum(goodstable == null ? "-1" : "" + goodstable.getType(), goodstable == null ? "-1" : "" + goodstable.getGoodsid(), sum);
                if (max < sum) {
                    ZhuFrame.getZhuJpanel().addPrompt2("你背包已不足");
                    return;
                }

                LoginResult loginResult = RoleData.getRoleData().getLoginResult();
                int jg = Integer.parseInt(this.goodDetailedJpanel.getXiaohaoXianyu().getText());
                if ("5".equals(this.goodDetailedJpanel.getEshop().getEshoptype())) {
                    if (loginResult.getMoney() < jg) {
                        ZhuFrame.getZhuJpanel().addPrompt2("没有足够的积分!");
                        return;
                    }
                } else if (loginResult.getCodecard().longValue() < (long)jg) {
                    ZhuFrame.getZhuJpanel().addPrompt2("没有足够的仙玉!");
                    return;
                }

                try {
                    BuyShopBean bean = new BuyShopBean();
                    bean.setAte(0);
                    bean.setCd(this.goodDetailedJpanel.getEshop().getEshopid());
                    bean.setSum(sum);
                    String senmes = Agreement.getAgreement().nbuyAgreement(GsonUtil.getGsonUtil().getgson().toJson(bean));
                    SendMessageUntil.toServer(senmes);
                } catch (Exception var12) {
                    var12.printStackTrace();
                }
            } else {
                int goodsPrice;
                if (this.caozuo == 2) {
                    if (this.wupinCount >= 999) {
                        ZhuFrame.getZhuJpanel().addPrompt2("最大数量999");
                        return;
                    }

                    goodsPrice = Integer.valueOf(this.goodDetailedJpanel.getWupinPrice().getText());
                    ++this.wupinCount;
                    this.goodDetailedJpanel.getGoumaiCount().setText(String.valueOf(this.wupinCount));
                    this.goodDetailedJpanel.getXiaohaoXianyu().setText(String.valueOf(goodsPrice * this.wupinCount));
                    this.goodDetailedJpanel.getPriceVal().setText(goodsPrice * this.wupinCount + this.goodDetailedJpanel.getNowMoneyType());
                } else if (this.caozuo == 3) {
                    if (this.wupinCount <= 0) {
                        ZhuFrame.getZhuJpanel().addPrompt2("数量为零了");
                        return;
                    }

                    goodsPrice = Integer.valueOf(this.goodDetailedJpanel.getWupinPrice().getText());
                    --this.wupinCount;
                    this.goodDetailedJpanel.getGoumaiCount().setText(String.valueOf(this.wupinCount));
                    this.goodDetailedJpanel.getXiaohaoXianyu().setText(String.valueOf(goodsPrice * this.wupinCount));
                    this.goodDetailedJpanel.getPriceVal().setText(goodsPrice * this.wupinCount + this.goodDetailedJpanel.getNowMoneyType());
                }
            }
        } else if (this.caozuo >= 20 && this.caozuo <= 22) {
            String url;
            if (this.caozuo == 20) {
                url = Agreement.getAgreement().TaskNAgreement("Y10=6");
                SendMessageUntil.toServer(url);
            } else if (this.caozuo == 21 || this.caozuo == 22) {
                try {
                    url = (new DownLoadTxt()).GetServerTxt("yueka.txt");
                    if (StringUtil.isNullOrEmpty(url)) {
                        ZhuFrame.getZhuJpanel().addPrompt2("暂未开放");
                        return;
                    }

                    StringBuffer buffer = new StringBuffer();
                    buffer.append(url);
                    Desktop desktop = Desktop.getDesktop();
                    URI uri = new URI(buffer.toString());
                    desktop.browse(uri);
                } catch (Exception var11) {
                    var11.printStackTrace();
                }
            }
        }

    }
}
